package apk.yoursms.ad;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Handler;
import android.util.Log;
import android.widget.LinearLayout;
import apk.yoursms.YourSmsActivity;
import apk.yoursms.settings.Statistics;

import com.google.ads.Ad;
import com.google.ads.AdListener;
import com.google.ads.AdRequest.ErrorCode;
import com.google.ads.AdView;

public class AdListenerPopUp implements AdListener {

    private Activity activity;

    public AdListenerPopUp(Activity activity, final LinearLayout LLAdmob,
	    final AdView adview) {
	this.activity = activity;
    }

    @Override
    public void onDismissScreen(Ad arg0) {
    }

    @Override
    public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
    }

    @Override
    public void onLeaveApplication(Ad arg0) {
	Statistics.setData("YourSms - ads click");
	final SharedPreferences prefs = YourSmsActivity.getPrefs();
	 

	Handler handler = new Handler();
	handler.postDelayed(new Runnable() {
	    public void run() {
		prefs.edit().putInt("ad_count", 0).commit();
		activity.finish();
		Log.d("AD", "RUN: Activity Finish");		
	    }
	}, 5000);
    }

    @Override
    public void onPresentScreen(Ad arg0) {
    }

    @Override
    public void onReceiveAd(Ad arg0) {
    }

}
